//
//  LocationClientOptionsModel.m
//  o_amap
//
//  Created by Q神 on 2021/4/12.
//

#import "LocationClientOptionsModel.h"

@implementation LocationClientOptionsModel

/**
 解析flutter端所设置的定位SDK参数
 */
- (BOOL)initWithOptionsForLocationManager:(AMapLocationManager *)locationManager {
    
    if(locationManager) {

        /// 持续定位是否返回逆地理信息，默认NO
        locationManager.locatingWithReGeocode = YES;

        /// 设置期望定位精度
        if (self.locationMode) {
          [locationManager setDesiredAccuracy:self.locationMode];
        }

        /// 设置定位的最小更新距离
        if (self.distanceFilter) {
            locationManager.distanceFilter = self.distanceFilter;
        }

        /// 指定定位是否会被系统自动暂停
        if ((BOOL)self.pausesLocationUpdatesAutomatically) {
//            NSLog(@"设置定位被系统自动暂停");
            locationManager.locatingWithReGeocode = YES;
        } else {
//            NSLog(@"设置定位不能被系统自动暂停");
            locationManager.locatingWithReGeocode = NO;
        }

        /// 设置是否允许后台定位
        if ((BOOL)self.allowsBackgroundLocationUpdates) {
//            NSLog(@"设置允许后台定位");
             locationManager.locatingWithReGeocode = YES;
        } else {
//            NSLog(@"设置不允许后台定位");
            locationManager.locatingWithReGeocode = NO;
            locationManager.distanceFilter = kCLDistanceFilterNone;
        }

        /// 设置定位超时时间
        if (self.locationTimeout) {
            [locationManager setLocationTimeout:self.locationTimeout];
        }

        /// 设置逆地理超时时间
        if (self.reGeocodeTimeout) {
            [locationManager setReGeocodeTimeout:self.reGeocodeTimeout];
        }
        
        return YES;

    }
    return NO;
}

@end
